from ecr_billing_tools import create_session_with_credentials, s3_copy_recursive, assume_role

session_name = "AWSCLI-Session"
# 生成 Session S3 Client
def create_role_s3_client(aws_role_arn):
    # 假设角色并获取临时凭证
    credentials = assume_role(aws_role_arn, session_name)
    # 创建一个新的会话，使用临时凭证
    session = create_session_with_credentials(credentials)
    # 基于 Session 创建 s3 client
    return session.client('s3')

def sync_to_cur_bucket_ob(aws_role_arn, last_cur_bucket, customer_cur_bucket, manifest_json_name, last_cur_prefix_parent, new_last_cur_prefix):
    # 创建带有 Session 的 s3 client，主要用来切换 ARN
    s3 = create_role_s3_client(aws_role_arn)
    # 同步 S3 文件夹
    s3_copy_recursive(f"{last_cur_bucket}", f"{new_last_cur_prefix}", f"{customer_cur_bucket}", f"{new_last_cur_prefix}", s3)
    # 同步 S3 外侧的 Json 文件
    s3_copy_recursive(f"{last_cur_bucket}", f"{last_cur_prefix_parent}{manifest_json_name}", f"{customer_cur_bucket}", f"{last_cur_prefix_parent}{manifest_json_name}", s3)